package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Festival;
import org.hxyjs.entity.Festival;
import org.hxyjs.entity.Festival;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.FestivalService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 festivalController
@RequestMapping("/festivalController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /festivalController
public class FestivalController {
	@Resource
    FestivalService festivalService;
	@RequestMapping("/getAllFestival")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Festival> getAllFestival() throws Exception{
    	System.out.println("查询全部节日");
    	return festivalService.getAllFestivals();
    }



	@RequestMapping("/deleteFestivalByFno/{fno}")
	@ResponseBody
    public DTO<Festival> deleteFestivalByFno(@RequestBody @PathVariable("fno") String fno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(fno+"删除节日成功");
    	return festivalService.deleteFestivalByFno(fno);
    }


	@RequestMapping("/updateFestivalByFno")
	@ResponseBody
	public DTO<Festival> updateFestivalByFno(@RequestBody Festival festival) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改管理员成功");
		System.out.println(festival);
		return festivalService.updateFestivalByFno(festival);
	}

	@RequestMapping("/addFestivalByFno")
	@ResponseBody
	public DTO<Festival> addFestivalByFno(@RequestBody Festival festival) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加节日");
		return festivalService.addFestivalByFno(festival);
	}

	@RequestMapping("/getFestivalByFno/{fno}")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
	public DTO<Festival> getFestivalByFno(@PathVariable("fno")String fno) throws Exception{
		System.out.println("根据主键查询全部节日");
		return festivalService.getFestivalByFno(fno);
	}
	@RequestMapping("/getFestivalByPage")
	@ResponseBody
	public DTO<Festival> getFestivalByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页查询节日成功");
		return festivalService.getFestivalByPage(pageInfo);
	}

}
